package com.kmust.dream.wanderingdream.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductProperty;
import com.kmust.dream.wanderingdream.product.service.ProductPropertyService;
import com.kmust.dream.wanderingdream.product.mapper.ProductPropertyMapper;
import com.kmust.dream.wanderingdream.product.utils.ReturnUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
@Transactional
public class ProductPropertyServiceImpl extends ServiceImpl<ProductPropertyMapper, ProductProperty>
implements ProductPropertyService{

    @Override
    public ResultBean getAllProperties() {
        return ReturnUtils.getList(this.list());
    }

    @Override
    public ResultBean getPropertyById(Integer id) {
        return ReturnUtils.getOne(this.getById(id));
    }

    @Override
    public ResultBean getPropertyByProductId(Integer productId) {
        return ReturnUtils.getOne(this.list(new QueryWrapper<ProductProperty>().eq("product_id", productId)));
    }

    @Override
    public ResultBean addProductProperty(ProductProperty productProperty) {
        return ReturnUtils.add(this.save(productProperty));
    }

    @Override
    public ResultBean updateProductProperty(ProductProperty productProperty) {
        return ReturnUtils.update(this.updateById(productProperty));
    }

    @Override
    public ResultBean deleteProductProperty(Integer id) {
        return ReturnUtils.delete(this.removeById(id));
    }

    @Override
    public ResultBean getPropertyName(Integer productId) {
        QueryWrapper<ProductProperty> select = new QueryWrapper<ProductProperty>().eq("product_id", productId).select("DISTINCT product_property_name_id");
        return ReturnUtils.getList(list(select));
    }
}




